package com.yuneec.droneservice.command;

import com.yuneec.droneservice.request.IResponse;

import java.nio.charset.Charset;

public class ReadSN extends BaseCommand {
    public ReadSN() {
        super(MAV_RC_COMMAND.MAV_RC_CMD_READ_SN);
    }

    @Override
    public IResponse toResponse(byte[] data, int off, int len) {
        int code = data[off + 1] & 0xff;
        IResponse<String> response = new IResponse(ids(), code);
        if (code == MAV_RC_ERROR_CODE.MAV_RC_ERR_SUCCESS) {
            int snLen = data[off + 2] & 0xff;
            if (snLen > 0) {
                String sn = new String(data, off + 3, snLen, Charset.forName("utf8"));
                response.setParam(sn);
            }
        }
        return response;
    }
}
